package com.ghline.caloncabe.model;

import java.util.List;

import com.ghline.caloncabe.GameView;


import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Rect;

public class TempSprite {

	private static final int BMP_ROWS = 3;
    private static final int BMP_COLUMNS = 1;
    private int currentFrame = 0;
    private int width;
    private int height;
	private int x = 0;
	private int y = 0;
	private Bitmap bmp;
	private int life = 2;
	private List<TempSprite> temps;

	public TempSprite(List<TempSprite> temps, GameView gameView, int x,	int y, Bitmap bmp) {
		this.x = x;
		this.y = y;
		this.bmp = bmp;
		this.temps = temps;
		this.width = bmp.getWidth() / BMP_COLUMNS;
        this.height = bmp.getHeight() / BMP_ROWS;
	}

	public void draw(Canvas canvas) {
		update();
		int srcX = 0 * width;
        int srcY = currentFrame * height;
        Rect src = new Rect(srcX, srcY, srcX + width, srcY + height);
        Rect dst = new Rect(x, y, x + width, y + height);
		canvas.drawBitmap(bmp, src, dst, null);
	}

	private void update() {
		currentFrame = ++currentFrame % BMP_ROWS;
		if (--life < 1) {
			temps.remove(this);
		}
	}
}
